import java.io.*;
import java.net.*;
import java.util.*;
import java.security.Security;
import java.security.Provider;
import javax.net.ssl.*;
public class httpConnecterTest {    

    private String authUrl               = null;
    private StringBuffer connMessageBf   = new StringBuffer();
    private StringBuffer returnMessageBf = new StringBuffer();

    public static void main(String[] args) {

	if (args.length !=1) {
	    System.out.println("=============================");
	    System.out.println("[url]");
	    System.out.println("=============================");
	    System.exit(0);
	}

	httpConnecterTest c = new httpConnecterTest ();
	c.setUrl(args[0]);
	while ((c.connecting()).equals("ok")){
	    c.connecting();
	}
    }

    public void setUrl (String url) {
	authUrl = url;
    }


    public String getConnMessage () {
	return connMessageBf.toString();
    }

    public String getReturnMessage () {
	return returnMessageBf.toString();
    }

    public String connecting () {
        
	HttpURLConnection httpConnection = null;

	try {            

	    URL url = new URL (authUrl);
            
	    try {                
		httpConnection = (HttpURLConnection)url.openConnection();
       	        httpConnection.connect(); 
		
                connMessageBf.append("ResponseCode="+httpConnection.getResponseCode());
		if (httpConnection.getResponseCode()!=200) {
		    System.out.println("Connection lost!!!!!!!!!!!");
		    System.exit(0);
		}
		else {
		    System.out.println("Connection ok");
		    return "ok";
		}
	    } catch (IOException ioe) {                
		System.out.println("Error1="+ioe.getMessage()); 
		System.exit(1);         
	    }        
	} catch (MalformedURLException mue) {            
	    System.out.println("Error2="+mue.getMessage());            
	    System.exit(1);         
	} catch (Exception e) {
	    System.out.println("Error3="+e.getMessage());            
	    e.printStackTrace();            
	    System.exit(1);         
	} 
	return "not ok";   
    }
}






